package com.chinasoft.reposearch.controller;

import com.chinasoft.reposearch.entity.ResponseResult;
import com.chinasoft.reposearch.entity.po.LanguageCount;
import com.chinasoft.reposearch.service.LanguageCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequiredArgsConstructor
@CrossOrigin
public class LanguageController {
    private final LanguageCountService languageCountService;

    @Autowired
    public LanguageController(LanguageCountService languageCountService) {
        this.languageCountService = languageCountService;
    }

    /**
     * GET /language-count?year=&month=
     * 查询所有语言 某个年月的 列表和数目
     */
    @GetMapping("/language-count")
    public ResponseResult getLanguageCount(@RequestParam(required = false) Integer year, @RequestParam(required = false) Integer month) {
        return languageCountService.getLanguageCount(year, month);
    }

    /**
     * GET /language-trending?lang=&year=
     * 查询某个语言 所有年月的 列表和数目
     */
    @GetMapping("/language-trending")
    public List<LanguageCount> getLanguageTrending(@RequestParam(required = false) String lang, @RequestParam(required = false) Integer year) {
        return languageCountService.getLanguageTrending(lang, year);
    }

    @GetMapping("/languages")
    public List<String> getLanguages() {
        return languageCountService.getLanguages();
    }

    @GetMapping("/language-trending-years")
    public List<LanguageCount> getLanguageTrendingYears(String lang, Integer start, Integer end) {
        return languageCountService.getLanguageTrendingYears(lang, start, end);
    }
}
